import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 牛孟俊
 * Date: 2023-11-07
 * Time: 16:51
 */

class Person {
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    /**
     * HashCode 找位置的
     * @return
     */
    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");
        Person person3 = new Person("2254");
        Person person4 = new Person("1264");
        Person person5 = new Person("1454");
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }

    public static void main3(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1,11);
        hashBucket.put(2,22);
        hashBucket.put(3,33);
        hashBucket.put(4,44);
        hashBucket.put(12,122);
        hashBucket.put(13,133);
        hashBucket.put(14,144);
        hashBucket.put(5,55);
        hashBucket.put(16,166);

        System.out.println(hashBucket.get(16));
    }


    //387. 字符串中的第一个唯一字符
    public int firstUniqChar(String s) {
        int[] countArray = new int[26];
        for(int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            countArray[ch - 'a']++;
        }
        for(int i = 0;i < s.length();i++) {
            char ch = s.charAt(i);
            if(countArray[ch - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main2(String[] args) {
        Set<String> strings = new TreeSet<>();
        strings.add("hello");
        strings.add("abcd");
        strings.add("abcd");//set中的元素是不可以重复的
        strings.add("nmm");
        System.out.println("===============");

        Iterator<String> it = strings.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public static void main1(String[] args) {
        Map<String,Integer> map = new TreeMap<>();
        //put插入元素
        map.put("hello",2);//hello 这个单词出现两次
        map.put("abcd",3);//abcd 这个单词出现了3次
        //put相当于在搜索树当中插入元素，比较的是key的大小，所以key一定实现了Comparable接口
        map.put("abcde",4);
        map.put("abcdf",5);
        map.put("abcdg",6);
        map.put("abcdh",7 );



       /* Set<String> set = map.keySet();//返回值是一个Set类型的
        Collection<Integer> collection = map.values();*/
        Set<Map.Entry<String,Integer>> entrySet = map.entrySet(); //拿出来之后就可以遍历这个数组了
        for(Map.Entry<String,Integer> entry : entrySet) {
            System.out.println("key: "+ entry.getKey() + " val:"+ entry.getValue());
        }
        System.out.println("================");

        //System.out.println(map.get("abcd"));
        //System.out.println(map.getOrDefault("abcde",6666));//树中没有abcd这个值，返回的是给定的默认值6666
        //System.out.println(map.getOrDefault("abcd",99999));//返回的是key对于的value值
        //System.out.println(map.remove("abcd"));//返回的是key对于的value值

    }
}
